import HTMLParser
import urllib
import re


urlString="http://www.db.ripe.net/whois?sol-ix"

urlText=[]

class ParseIXP(HTMLParser.HTMLParser):
    check = False
    
    def handle_starttag (self, tag, attrs):
        if tag == "pre":
            self.check = True
    
    def handle_data (self, data):
        
            # separo i dati mantenendo in data i separatori (pattern tra parentesi)
            
            data = re.split("(\s\d+\s+\.)", data)
            for i in data:
                
                # considero solo gli elementi di data che sono i separatori, ossia ASN
                s=re.match("^\s(\d+)\s+\.$", i)
                if(s):
                    i=s.group(1)            
                    if i not in urlText:
                        urlText.append(i)
            self.check = False
         
            
lparser=ParseIXP()
lparser.feed(urllib.urlopen(urlString).read())
filePath="ixp_members.txt"
file = open(filePath,"a")
for item in urlText:
    #print item
    print >> file, "73 %s" % item
file.close()